<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="renderer" content="webkit">

  
  <title>Android 10.0 状态栏系统图标显示分析 | 龙之叶的博客</title>

  <link rel="shortcut icon" href="/images/favicon.png">
  <link rel="alternate" href="/atom.xml" title="龙之叶的博客" type="application/atom+xml">
  <meta name="description" content="Android 10.0 状态栏系统图标显示分析">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 10.0 状态栏系统图标显示分析">
<meta property="og:url" content="http://longzhiye.top/2023/11/26/2023-11-26/index.html">
<meta property="og:site_name" content="龙之叶的博客">
<meta property="og:description" content="Android 10.0 状态栏系统图标显示分析">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-11-25T16:00:00.000Z">
<meta property="article:modified_time" content="2024-08-29T02:40:34.914Z">
<meta property="article:author" content="龙之叶">
<meta property="article:tag" content="Android">
<meta property="article:tag" content="SystemUI">
<meta property="article:tag" content="framework">
<meta name="twitter:card" content="summary">

  <meta name="keywords" content=",Android,SystemUI,framework">
  <meta name="format-detection" content="telephone=no,email=no">
  <meta name="theme-color" content="#9C27B0">

  <meta name="mobile-web-app-capable" content="yes">
  <meta name="application-name" content="龙之叶的博客">
  <meta name="msapplication-starturl" content="http://longzhiye.top/2023/11/26/2023-11-26/">
  <meta name="msapplication-navbutton-color" content="#9C27B0">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-title" content="龙之叶的博客">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon" href="/images/favicon.png">

  
    <link rel="canonical" href="http://longzhiye.top/2023/11/26/2023-11-26/">
  

  
  

  
  
  

  
<link rel="stylesheet" href="/css/mdui.css">
<link rel="stylesheet" href="/css/style.css">

  
<link rel="stylesheet" href="/custom.css">

<meta name="generator" content="Hexo 5.4.2"></head>

<body class="mdui-appbar-with-toolbar mdui-theme-primary-indigo mdui-theme-accent-pink">
  <script>var a=localStorage.getItem("mdui-theme-layout-dark");if(a){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>if(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches){document.getElementsByTagName("body")[0].className+=" mdui-theme-layout-dark"};</script>
  <script>var a=localStorage.getItem("mdui-drawer-close");if(!a){document.getElementsByTagName("body")[0].className+=" mdui-drawer-body-left"};</script>
  <header id="header" class="mdui-appbar mdui-appbar-fixed mdui-appbar-scroll-hide mdui-appbar-inset">
  <div class="mdui-toolbar mdui-color-theme">
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-drawer="{target: '#sidebar', swipe: true}"><i class="mdui-icon material-icons">menu</i></a>
    <a href="/" class="mdui-typo-headline">龙之叶的博客</a>
    <div class="mdui-toolbar-spacer"></div>
    <a href="javascript:;" class="mdui-btn mdui-btn-icon" mdui-dialog="{target: '#search'}" mdui-tooltip="{content: '搜索'}"><i class="mdui-icon material-icons">search</i></a>
	<!--
    <a href="/atom.xml" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'RSS'}"><i class="mdui-icon material-icons">rss_feed</i></a>
	-->
  </div>
</header>
<div class="mdui-dialog" id="search">
  
    <div class="search-form">
      <input type="search" class="search-form-input" placeholder="请输入关键字">
    </div>
    <div class="search-result" data-resource="/search.xml"></div>
  
</div>

  <aside id="sidebar" class="mdui-drawer mdui-drawer-full-height">
  <script>var a=localStorage.getItem("mdui-drawer-close");if(a){document.getElementById("sidebar").className+=" mdui-drawer-close"};</script>
  <div class="mdui-grid-tile">
    <img src="/images/banner.png" style="height: 160px;">
    <img src="/images/avatar.png" class="avatar-animation" style="position: absolute; top: 10%; left: 24px; width: 64px; height: 64px; border: 2px solid #fff; border-radius: 50%;background-color:#fff;">
    <div class="mdui-grid-tile-actions">
      <div class="mdui-grid-tile-text">
        <div class="mdui-grid-tile-title">龙之叶</div>
        <div class="mdui-grid-tile-subtitle"><i class="mdui-icon material-icons">art_track</i>生命不息，折腾不止</div>
      </div>
      
        <div class="mdui-grid-tile-buttons">
          <a href="mailto:longzhiye163@163.com" class="mdui-btn mdui-btn-icon" mdui-tooltip="{content: 'longzhiye163@163.com'}"><i class="mdui-icon material-icons">email</i></a>
        </div>
      
    </div>
  </div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    <a href="/" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-blue">home</i>
      <div class="mdui-list-item-content">主页</div>
    </a>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-0");if(a){document.getElementsByClassName("mdui-collapse-item")[0].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-deep-orange">archive</i>
        <div class="mdui-list-item-content">归档</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/archives/2025/07/">七月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/06/">六月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/03/">三月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/02/">二月 2025<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2025/01/">一月 2025<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/10/">十月 2024<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/09/">九月 2024<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/08/">八月 2024<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/03/">三月 2024<span class="mdui-ripple sidebar_archives-count">5</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/02/">二月 2024<span class="mdui-ripple sidebar_archives-count">11</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2024/01/">一月 2024<span class="mdui-ripple sidebar_archives-count">9</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/12/">十二月 2023<span class="mdui-ripple sidebar_archives-count">10</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/11/">十一月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/10/">十月 2023<span class="mdui-ripple sidebar_archives-count">8</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/09/">九月 2023<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/08/">八月 2023<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/06/">六月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/05/">五月 2023<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/04/">四月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/03/">三月 2023<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2023/02/">二月 2023<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/09/">九月 2022<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2022/08/">八月 2022<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/04/">四月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/03/">三月 2017<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/02/">二月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2017/01/">一月 2017<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/12/">十二月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/11/">十一月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/10/">十月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/archives/2016/08/">八月 2016<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-1");if(a){document.getElementsByClassName("mdui-collapse-item")[1].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-green">class</i>
        <div class="mdui-list-item-content">分类</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术<span class="mdui-ripple sidebar_archives-count">98</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E7%94%9F%E6%B4%BB/">生活<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E8%B5%84%E8%AE%AF/">资讯<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/categories/%E9%80%9A%E7%9F%A5/">通知<span class="mdui-ripple sidebar_archives-count">4</span></a>
        
      </div>
    </div>
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-2");if(a){document.getElementsByClassName("mdui-collapse-item")[2].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-brown">bookmark</i>
        <div class="mdui-list-item-content">标签</div>
        <i class="mdui-collapse-item-arrow mdui-icon material-icons">keyboard_arrow_down</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
        <a class="mdui-ripple sidebar_archives-link" href="/tags/ANR/" rel="tag">ANR<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/APP/" rel="tag">APP<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android/" rel="tag">Android<span class="mdui-ripple sidebar_archives-count">89</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android12/" rel="tag">Android12<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android13/" rel="tag">Android13<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Android14/" rel="tag">Android14<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AndroidStudio/" rel="tag">AndroidStudio<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/AutoDraw/" rel="tag">AutoDraw<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Crash/" rel="tag">Crash<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Foxmail/" rel="tag">Foxmail<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Framework/" rel="tag">Framework<span class="mdui-ripple sidebar_archives-count">20</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GPS%E8%BD%A8%E8%BF%B9%E5%9B%BE/" rel="tag">GPS轨迹图<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Git/" rel="tag">Git<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/GitHub/" rel="tag">GitHub<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Google/" rel="tag">Google<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Hexo/" rel="tag">Hexo<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Java/" rel="tag">Java<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Kernel/" rel="tag">Kernel<span class="mdui-ripple sidebar_archives-count">4</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Launcher/" rel="tag">Launcher<span class="mdui-ripple sidebar_archives-count">17</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Lib/" rel="tag">Lib<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Linux/" rel="tag">Linux<span class="mdui-ripple sidebar_archives-count">18</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Markdown/" rel="tag">Markdown<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Material-Design/" rel="tag">Material Design<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OS-X/" rel="tag">OS X<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/OTA/" rel="tag">OTA<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/QuickTime/" rel="tag">QuickTime<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SSH/" rel="tag">SSH<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Settings/" rel="tag">Settings<span class="mdui-ripple sidebar_archives-count">6</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/SystemUI/" rel="tag">SystemUI<span class="mdui-ripple sidebar_archives-count">19</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Ubuntu/" rel="tag">Ubuntu<span class="mdui-ripple sidebar_archives-count">7</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WPS/" rel="tag">WPS<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Wifi/" rel="tag">Wifi<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/WindTerm/" rel="tag">WindTerm<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/Windows/" rel="tag">Windows<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/androidmk/" rel="tag">androidmk<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/blog/" rel="tag">blog<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/build/" rel="tag">build<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/feel/" rel="tag">feel<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/framework/" rel="tag">framework<span class="mdui-ripple sidebar_archives-count">50</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/git/" rel="tag">git<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/inotify/" rel="tag">inotify<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/life/" rel="tag">life<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/ninja/" rel="tag">ninja<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/rsync/" rel="tag">rsync<span class="mdui-ripple sidebar_archives-count">2</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/standard/" rel="tag">standard<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/test/" rel="tag">test<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1/" rel="tag">企业微信<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag">操作系统<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试<span class="mdui-ripple sidebar_archives-count">1</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码<span class="mdui-ripple sidebar_archives-count">3</span></a><a class="mdui-ripple sidebar_archives-link" href="/tags/%E7%94%9F%E6%B4%BB%E6%84%9F%E6%82%9F/" rel="tag">生活感悟<span class="mdui-ripple sidebar_archives-count">1</span></a>
        
      </div>
    </div>
    <a href="/about" class="mdui-list-item mdui-ripple">
      <i class="mdui-list-item-icon mdui-icon material-icons mdui-text-color-purple">person</i>
      <div class="mdui-list-item-content">关于</div>
    </a>
  </div>

  <div class="mdui-divider"></div>

  <div class="mdui-list" mdui-collapse="{accordion: true}">
    
      <a href="/timeline" class="mdui-list-item mdui-ripple">时间轴</a>
    
    <div class="mdui-collapse-item">
      <script>var a=localStorage.getItem("mdui-collapse-item-3");if(a){document.getElementsByClassName("mdui-collapse-item")[3].className+=" mdui-collapse-item-open"};</script>
      <div class="mdui-collapse-item-header mdui-list-item mdui-ripple">
        <div class="mdui-list-item-content">友情链接</div>
        <i class="mdui-list-item-icon mdui-icon material-icons">link</i>
      </div>
      <div class="mdui-collapse-item-body mdui-list mdui-list-dense">
        
          <a href="http://www.niemingzhao.top" target="_blank" class="mdui-list-item mdui-p-l-2 mdui-text-color-theme-accent mdui-ripple" style="justify-content: center;">聂明照的博客</a>
        
        
      </div>
    </div>
  </div>
</aside>

  <main id="main" class="mdui-m-t-5 fadeIn animated">
  
<link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css">

  <style>#main article .mdui-card-content .center-block{display:block!important;margin-right:auto!important;margin-left:auto!important}</style>
  <style>#main article .mdui-card-content .text-center{text-align:center!important}</style>
  <article class="mdui-card mdui-m-b-5">
    <header class="mdui-card-media">
      <img src="/images/random/material-9.png" style="max-height: 240px;">
      <div class="mdui-card-media-covered">
        <div class="mdui-card-primary">
          <div class="mdui-card-primary-title">Android 10.0 状态栏系统图标显示分析</div>
          <div class="mdui-card-primary-subtitle"><i class="iconfont">&#xe697;</i> 2023-11-26 / <i class="iconfont">&#xe601;</i> 龙之叶 &nbsp;&nbsp; <span id="busuanzi_container_page_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_page_pv"></span></span></div>
        </div>
      </div>
      <div class="mdui-card-menu">
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#qrcode', align: 'right'}"><i class="mdui-icon material-icons">devices</i></button>
          <ul class="mdui-menu" id="qrcode">
            
              <li class="mdui-menu-item"><a class="mdui-text-center mdui-ripple">发送到手机</a></li>
            
            <li class="mdui-menu-item" disabled>
              
                <img src="//qr.liantu.com/api.php?w=246&m=10&text=http://longzhiye.top/2023/11/26/2023-11-26/">
              
            </li>
          </ul>
        
        
          <button class="mdui-btn mdui-btn-icon mdui-text-color-white" mdui-menu="{target: '#share_menu', align: 'right'}"><i class="mdui-icon material-icons">share</i></button>
          <ul class="mdui-menu" id="share_menu">
            <li class="mdui-menu-item">
              <a href="https://service.weibo.com/share/share.php?appkey=&title=Android 10.0 状态栏系统图标显示分析&url=http://longzhiye.top/2023/11/26/2023-11-26/&pic=http://longzhiye.top/images/favicon.png&searchPic=false&style=simple" target="_blank" class="mdui-ripple">分享到 Weibo</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://twitter.com/intent/tweet?text=Android 10.0 状态栏系统图标显示分析&url=http://longzhiye.top/2023/11/26/2023-11-26/&via=龙之叶" target="_blank" class="mdui-ripple">分享到 Twitter</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.facebook.com/sharer/sharer.php?u=http://longzhiye.top/2023/11/26/2023-11-26/" target="_blank" class="mdui-ripple">分享到 Facebook</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://plus.google.com/share?url=http://longzhiye.top/2023/11/26/2023-11-26/" target="_blank" class="mdui-ripple">分享到 Google+</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://www.linkedin.com/shareArticle?mini=true&url=http://longzhiye.top/2023/11/26/2023-11-26/&title=Android 10.0 状态栏系统图标显示分析" target="_blank" class="mdui-ripple">分享到 LinkedIn</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://connect.qq.com/widget/shareqq/index.html?site=龙之叶的博客&title=Android 10.0 状态栏系统图标显示分析&pics=http://longzhiye.top/images/favicon.png&url=http://longzhiye.top/2023/11/26/2023-11-26/" target="_blank" class="mdui-ripple">分享到 QQ</a>
            </li>
            <li class="mdui-menu-item">
              <a href="https://telegram.me/share/url?url=http://longzhiye.top/2023/11/26/2023-11-26/&text=Android 10.0 状态栏系统图标显示分析" target="_blank" class="mdui-ripple">分享到 Telegram</a>
            </li>
          </ul>
        
      </div>
    </header>
    <div class="mdui-card-content mdui-typo">
      <p>SystemUI中StatusBar的图标控制器实现类为StatusBarIconControllerImpl，其继承了StatusBarIconController的接口，用于跟踪所有图标的状态，并将对应的状态发送给注册的图标管理器(IconManagers)。当我们在StatusBar中获取到它的实例后，还会将它传给PhoneStatusBarPolicy和StatusBarSignalPolicy对象。PhoneStatusBarPolicy控制启动时装载哪些图标（蓝牙，定位等），而StatusBarSignalPolicy控制网络信号图标（移动网络，WiFi，以太网）的变化。<br>一起来看 StatuBar 的 start() 方法：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarSignalPolicy.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">start</span><span class="params">()</span> &#123;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// 创建整个SystemUI视图并添加到WindowManager中</span></span><br><span class="line">    createAndAddWindows();<span class="comment">//这个重点方法，创建相关的视图</span></span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// Lastly, call to the icon policy to install/update all the icons.</span></span><br><span class="line">    mIconPolicy.init();</span><br><span class="line">    mSignalPolicy = <span class="keyword">new</span> <span class="title class_">StatusBarSignalPolicy</span>(mContext, mIconController);</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里的 mIconPolicy 就是 PhoneStatusBarPolicy对象，mSignalPolicy  就是 StatusBarSignalPolicy 对象。我们这里以 StatusBarSignalPolicy  为例去研究。<br>StatusBarSignalPolicy实现了NetworkControllerImpl.SignalCallback接口，SignalCallback接口定义在NetworkControllerImpl实现的接口NetworkController中。<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Inject</span></span><br><span class="line"><span class="keyword">public</span> <span class="title function_">NetworkControllerImpl</span><span class="params">(Context context, <span class="meta">@Background</span> Looper bgLooper,</span></span><br><span class="line"><span class="params">        DeviceProvisionedController deviceProvisionedController,</span></span><br><span class="line"><span class="params">        BroadcastDispatcher broadcastDispatcher, ConnectivityManager connectivityManager,</span></span><br><span class="line"><span class="params">        TelephonyManager telephonyManager, WifiManager wifiManager,</span></span><br><span class="line"><span class="params">        NetworkScoreManager networkScoreManager)</span> &#123;</span><br><span class="line">    <span class="built_in">this</span>(context, connectivityManager,</span><br><span class="line">            telephonyManager,</span><br><span class="line">            wifiManager,</span><br><span class="line">            networkScoreManager,</span><br><span class="line">            SubscriptionManager.from(context), Config.readConfig(context), bgLooper,</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">CallbackHandler</span>(),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">AccessPointControllerImpl</span>(context),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">DataUsageController</span>(context),</span><br><span class="line">            <span class="keyword">new</span> <span class="title class_">SubscriptionDefaults</span>(),</span><br><span class="line">            deviceProvisionedController,</span><br><span class="line">            broadcastDispatcher);</span><br><span class="line">    mReceiverHandler.post(mRegisterListeners);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">final</span> <span class="type">Runnable</span> <span class="variable">mRegisterListeners</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Runnable</span>() &#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">run</span><span class="params">()</span> &#123;</span><br><span class="line">        registerListeners();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">void</span> <span class="title function_">registerListeners</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; mMobileSignalControllers.size(); i++) &#123;</span><br><span class="line">        <span class="type">MobileSignalController</span> <span class="variable">mobileSignalController</span> <span class="operator">=</span> mMobileSignalControllers.valueAt(i);</span><br><span class="line">        mobileSignalController.registerListener();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (mSubscriptionListener == <span class="literal">null</span>) &#123;</span><br><span class="line">        mSubscriptionListener = <span class="keyword">new</span> <span class="title class_">SubListener</span>();</span><br><span class="line">    &#125;</span><br><span class="line">    mSubscriptionManager.addOnSubscriptionsChangedListener(mSubscriptionListener);</span><br><span class="line">    mPhone.listen(mPhoneStateListener, LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE);</span><br><span class="line">    <span class="comment">// broadcasts</span></span><br><span class="line">    <span class="type">IntentFilter</span> <span class="variable">filter</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">IntentFilter</span>();</span><br><span class="line">    <span class="comment">// wifi相关</span></span><br><span class="line">    <span class="comment">// wifi信号强度广播</span></span><br><span class="line">    filter.addAction(WifiManager.RSSI_CHANGED_ACTION);</span><br><span class="line">    <span class="comment">// wifi状态变化广播</span></span><br><span class="line">    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);</span><br><span class="line">    <span class="comment">// wifi连接状态改变</span></span><br><span class="line">    filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 移动网络相关</span></span><br><span class="line">    <span class="comment">// SIM卡状态改变</span></span><br><span class="line">    filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);</span><br><span class="line">    <span class="comment">// 数据语音订阅修改</span></span><br><span class="line">    filter.addAction(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED);</span><br><span class="line">    filter.addAction(TelephonyIntents.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);</span><br><span class="line">    filter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);</span><br><span class="line">    filter.addAction(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION);</span><br><span class="line">    <span class="comment">// 连接状态相关</span></span><br><span class="line">    <span class="comment">// 网络连接状态发生变化</span></span><br><span class="line">    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);</span><br><span class="line">    <span class="comment">// 网络连接可能不好</span></span><br><span class="line">    filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);</span><br><span class="line">    <span class="comment">// 切换飞行模式时</span></span><br><span class="line">    filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);</span><br><span class="line">    filter.addAction(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);</span><br><span class="line">    mContext.registerReceiver(<span class="built_in">this</span>, filter, <span class="literal">null</span>, mReceiverHandler);</span><br><span class="line">    mListening = <span class="literal">true</span>;</span><br><span class="line">    <span class="comment">// 省略部分代码......</span></span><br><span class="line">    <span class="comment">// 4.更新移动网络控制器</span></span><br><span class="line">    updateMobileControllers();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在NetworkControllerImpl 的构造方法里，最终会调用到：registerListeners() 方法进行广播的注册。<br>广播处理：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onReceive</span><span class="params">(Context context, Intent intent)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (CHATTY) &#123;</span><br><span class="line">        Log.d(TAG, <span class="string">&quot;onReceive: intent=&quot;</span> + intent);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">final</span> <span class="type">String</span> <span class="variable">action</span> <span class="operator">=</span> intent.getAction();</span><br><span class="line">    <span class="keyword">switch</span> (action) &#123;</span><br><span class="line">        <span class="keyword">case</span> ConnectivityManager.CONNECTIVITY_ACTION:</span><br><span class="line">        <span class="keyword">case</span> ConnectivityManager.INET_CONDITION_ACTION:</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> Intent.ACTION_AIRPLANE_MODE_CHANGED:</span><br><span class="line">                <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> TelephonyManager.ACTION_DEFAULT_VOICE_SUBSCRIPTION_CHANGED:</span><br><span class="line">            <span class="comment">// We are using different subs now, we might be able to make calls.</span></span><br><span class="line">                <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> TelephonyManager.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED:</span><br><span class="line">            <span class="comment">// Notify every MobileSignalController so they can know whether they are the</span></span><br><span class="line">            <span class="comment">// data sim or not.</span></span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> Intent.ACTION_SIM_STATE_CHANGED:</span><br><span class="line">            <span class="comment">// Avoid rebroadcast because SysUI is direct boot aware.</span></span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> Intent.ACTION_SERVICE_STATE:</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED:</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> ImsManager.ACTION_IMS_SERVICE_UP:</span><br><span class="line">        <span class="keyword">case</span> ImsManager.ACTION_IMS_SERVICE_DOWN:</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> ACTION_HIGH_DEF_AUDIO_SUPPORT:</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> ACTION_MODEM_CHANGE:</span><br><span class="line">            <span class="comment">// 省略部分代码......</span></span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">            <span class="type">int</span> <span class="variable">subId</span> <span class="operator">=</span> intent.getIntExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX,</span><br><span class="line">                    SubscriptionManager.INVALID_SUBSCRIPTION_ID);</span><br><span class="line">            <span class="keyword">if</span> (SubscriptionManager.isValidSubscriptionId(subId)) &#123;</span><br><span class="line">                <span class="keyword">if</span> (mMobileSignalControllers.indexOfKey(subId) &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">                    mMobileSignalControllers.get(subId).handleBroadcast(intent);</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="comment">// Can&#x27;t find this subscription...  We must be out of date.</span></span><br><span class="line">                    updateMobileControllers();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="comment">// wifi状态图标处理</span></span><br><span class="line">                <span class="comment">// No sub id, must be for the wifi.</span></span><br><span class="line">                mWifiSignalController.handleBroadcast(intent);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里以 wifi状态图标处理 为例；接下来看WifiSignalController#handleBroadcast():<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">handleBroadcast</span><span class="params">(Intent intent)</span> &#123;</span><br><span class="line">    mWifiTracker.handleBroadcast(intent);</span><br><span class="line">    mCurrentState.enabled = mWifiTracker.enabled;</span><br><span class="line">    mCurrentState.connected = mWifiTracker.connected;</span><br><span class="line">    mCurrentState.ssid = mWifiTracker.ssid;</span><br><span class="line">    mCurrentState.rssi = mWifiTracker.rssi;</span><br><span class="line">    mCurrentState.level = mWifiTracker.level;</span><br><span class="line">    mCurrentState.statusLabel = mWifiTracker.statusLabel;</span><br><span class="line">    notifyListenersIfNecessary();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>在WifiSignalController#handleBroadcast()方法中，就两个实现，一个是获取 WiFi 的状态，一个是通知更新状态。<br>我们直接看通知SignalController# notifyListenersIfNecessary() :<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/SignalController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">notifyListenersIfNecessary</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (isDirty()) &#123;</span><br><span class="line">        saveLastState();    <span class="comment">// 保持此时的状态</span></span><br><span class="line">        notifyListeners();    <span class="comment">// 通知监听器</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title function_">notifyListeners</span><span class="params">()</span> &#123;</span><br><span class="line">    notifyListeners(mCallbackHandler);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title function_">notifyListeners</span><span class="params">(SignalCallback callback)</span>;</span><br></pre></td></tr></table></figure>
<p>notifyListener()方法的实现在WifiSignalController类中：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiSignalController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">notifyListeners</span><span class="params">(SignalCallback callback)</span> &#123;</span><br><span class="line">    <span class="comment">// only show wifi in the cluster if connected or if wifi-only</span></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">visibleWhenEnabled</span> <span class="operator">=</span> mContext.getResources().getBoolean(</span><br><span class="line">            R.bool.config_showWifiIndicatorWhenEnabled);</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">wifiVisible</span> <span class="operator">=</span> mCurrentState.enabled &amp;&amp; (</span><br><span class="line">            (mCurrentState.connected &amp;&amp; mCurrentState.inetCondition == <span class="number">1</span>)</span><br><span class="line">                    || !mHasMobileDataFeature || mWifiTracker.isDefaultNetwork</span><br><span class="line">                    || visibleWhenEnabled);</span><br><span class="line">    <span class="type">String</span> <span class="variable">wifiDesc</span> <span class="operator">=</span> mCurrentState.connected ? mCurrentState.ssid : <span class="literal">null</span>;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">ssidPresent</span> <span class="operator">=</span> wifiVisible &amp;&amp; mCurrentState.ssid != <span class="literal">null</span>;</span><br><span class="line">    <span class="type">String</span> <span class="variable">contentDescription</span> <span class="operator">=</span> getTextIfExists(getContentDescription()).toString();</span><br><span class="line">    <span class="keyword">if</span> (mCurrentState.inetCondition == <span class="number">0</span>) &#123;</span><br><span class="line">        contentDescription += (<span class="string">&quot;,&quot;</span> + mContext.getString(R.string.data_connection_no_internet));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="type">IconState</span> <span class="variable">statusIcon</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">IconState</span>(wifiVisible, getCurrentIconId(), contentDescription);</span><br><span class="line">    <span class="type">IconState</span> <span class="variable">qsIcon</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">IconState</span>(mCurrentState.connected,</span><br><span class="line">            mWifiTracker.isCaptivePortal ? R.drawable.ic_qs_wifi_disconnected</span><br><span class="line">                    : getQsCurrentIconId(), contentDescription);</span><br><span class="line">    <span class="comment">// callback为 CallbackHandler对象</span></span><br><span class="line">    callback.setWifiIndicators(mCurrentState.enabled, statusIcon, qsIcon,</span><br><span class="line">            ssidPresent &amp;&amp; mCurrentState.activityIn, ssidPresent &amp;&amp; mCurrentState.activityOut,</span><br><span class="line">            wifiDesc, mCurrentState.isTransient, mCurrentState.statusLabel);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到，这里回调了StatusBarSignalPolicy#setWifiIndicators() 方法：<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarSignalPolicy.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setWifiIndicators</span><span class="params">(<span class="type">boolean</span> enabled, IconState statusIcon, IconState qsIcon,</span></span><br><span class="line"><span class="params">        <span class="type">boolean</span> activityIn, <span class="type">boolean</span> activityOut, String description, <span class="type">boolean</span> isTransient,</span></span><br><span class="line"><span class="params">        String statusLabel)</span> &#123;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">visible</span> <span class="operator">=</span> statusIcon.visible &amp;&amp; !mBlockWifi;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">in</span> <span class="operator">=</span> activityIn &amp;&amp; mActivityEnabled &amp;&amp; visible;</span><br><span class="line">    <span class="type">boolean</span> <span class="variable">out</span> <span class="operator">=</span> activityOut &amp;&amp; mActivityEnabled &amp;&amp; visible;</span><br><span class="line">    <span class="type">WifiIconState</span> <span class="variable">newState</span> <span class="operator">=</span> mWifiIconState.copy();</span><br><span class="line">    newState.visible = visible;</span><br><span class="line">    newState.resId = statusIcon.icon;</span><br><span class="line">    newState.activityIn = in;</span><br><span class="line">    newState.activityOut = out;</span><br><span class="line">    newState.slot = mSlotWifi;</span><br><span class="line">    newState.airplaneSpacerVisible = mIsAirplaneMode;</span><br><span class="line">    newState.contentDescription = statusIcon.contentDescription;</span><br><span class="line">    <span class="type">MobileIconState</span> <span class="variable">first</span> <span class="operator">=</span> getFirstMobileState();</span><br><span class="line">    newState.signalSpacerVisible = first != <span class="literal">null</span> &amp;&amp; first.typeId != <span class="number">0</span>;</span><br><span class="line">    updateWifiIconWithState(newState);</span><br><span class="line">    mWifiIconState = newState;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title function_">updateWifiIconWithState</span><span class="params">(WifiIconState state)</span> &#123;</span><br><span class="line">    <span class="keyword">if</span> (state.visible &amp;&amp; state.resId &gt; <span class="number">0</span>) &#123;</span><br><span class="line">        mIconController.setSignalIcon(mSlotWifi, state);</span><br><span class="line">        mIconController.setIconVisibility(mSlotWifi, <span class="literal">true</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        mIconController.setIconVisibility(mSlotWifi, <span class="literal">false</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>通过StatusBarIconController接口设置图标的套路都是一样的:</p>
<ul>
<li>获取图标名字</li>
<li>监听事件</li>
<li>通过StatusBarIconControllerImpl相应的方法设置图标。<br>接下来再看StatusBarIconControllerImpl#setSignalIcon()：</li>
</ul>
<p><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconControllerImpl.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Signal icons need to be handled differently, because they can be</span></span><br><span class="line"><span class="comment"> * composite views</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setSignalIcon</span><span class="params">(String slot, WifiIconState state)</span> &#123;</span><br><span class="line">    <span class="type">int</span> <span class="variable">index</span> <span class="operator">=</span> getSlotIndex(slot);</span><br><span class="line">    <span class="keyword">if</span> (state == <span class="literal">null</span>) &#123;</span><br><span class="line">        removeIcon(index, <span class="number">0</span>);</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="type">StatusBarIconHolder</span> <span class="variable">holder</span> <span class="operator">=</span> getIcon(index, <span class="number">0</span>);</span><br><span class="line">    <span class="keyword">if</span> (holder == <span class="literal">null</span>) &#123;</span><br><span class="line">        holder = StatusBarIconHolder.fromWifiIconState(state);</span><br><span class="line">        setIcon(index, holder);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        holder.setWifiState(state);</span><br><span class="line">        handleSet(index, holder);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>首先设置WiFi的状态信息，遍历mIconGroups分别执行StatusBarIconController接口中静态类IconManager中的onIconAdded()和onSetIconHolder()的回调。<br>IconManager用于将信息从StatusBarIconController转换为ViewGroup中的ImageViews(com.android.systemui.statusbar.AlphaOptimizedImageView)。<br>接着看IconManager中的onIconAdded()和onSetIconHolder()方法：这两个方法一个用于添加、一个用于更新。<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarIconController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">StatusBarIconController</span> &#123;</span><br><span class="line">    ....</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">DarkIconManager</span> <span class="keyword">extends</span> <span class="title class_">IconManager</span> &#123;</span><br><span class="line">        ....</span><br><span class="line">        <span class="keyword">public</span> <span class="title function_">DarkIconManager</span><span class="params">(LinearLayout linearLayout)</span> &#123;</span><br><span class="line">            <span class="comment">// 将布局传入IconManager</span></span><br><span class="line">            <span class="built_in">super</span>(linearLayout);</span><br><span class="line">            mIconHPadding = mContext.getResources().getDimensionPixelSize(</span><br><span class="line">                    R.dimen.status_bar_icon_padding);</span><br><span class="line">            mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class);</span><br><span class="line">        &#125;</span><br><span class="line">        ....</span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">onIconAdded</span><span class="params">(<span class="type">int</span> index, String slot, <span class="type">boolean</span> blocked,</span></span><br><span class="line"><span class="params">                                   StatusBarIconHolder holder)</span> &#123;</span><br><span class="line">            <span class="comment">// 调用到父类的addHolder方法</span></span><br><span class="line">            <span class="type">StatusIconDisplayable</span> <span class="variable">view</span> <span class="operator">=</span> addHolder(index, slot, blocked, holder);</span><br><span class="line">            ....</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">class</span> <span class="title class_">IconManager</span> <span class="keyword">implements</span> <span class="title class_">DemoMode</span> &#123;</span><br><span class="line">        ....</span><br><span class="line">        <span class="keyword">protected</span> <span class="keyword">final</span> ViewGroup mGroup;</span><br><span class="line">        <span class="keyword">protected</span> <span class="keyword">final</span> Context mContext;</span><br><span class="line">        <span class="keyword">public</span> <span class="title function_">IconManager</span><span class="params">(ViewGroup group)</span> &#123;</span><br><span class="line">            mGroup = group;</span><br><span class="line">            mContext = group.getContext();</span><br><span class="line">            mIconSize = mContext.getResources().getDimensionPixelSize(</span><br><span class="line">                    R.dimen.status_bar_height);</span><br><span class="line">            ....</span><br><span class="line">        &#125;</span><br><span class="line">        ....</span><br><span class="line">        <span class="keyword">protected</span> StatusIconDisplayable <span class="title function_">addHolder</span><span class="params">(<span class="type">int</span> index, String slot, <span class="type">boolean</span> blocked,</span></span><br><span class="line"><span class="params">                                                  StatusBarIconHolder holder)</span> &#123;</span><br><span class="line">            <span class="keyword">switch</span> (holder.getType()) &#123;</span><br><span class="line">                <span class="keyword">case</span> TYPE_ICON:</span><br><span class="line">                    <span class="keyword">return</span> addIcon(index, slot, blocked, holder.getIcon());</span><br><span class="line">                <span class="keyword">case</span> TYPE_WIFI:</span><br><span class="line">                    <span class="keyword">return</span> addSignalIcon(index, slot, holder.getWifiState());</span><br><span class="line">                <span class="keyword">case</span> TYPE_MOBILE:</span><br><span class="line">                    <span class="keyword">return</span> addMobileIcon(index, slot, holder.getMobileState());</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="meta">@VisibleForTesting</span></span><br><span class="line">        <span class="keyword">protected</span> StatusBarWifiView <span class="title function_">addSignalIcon</span><span class="params">(<span class="type">int</span> index, String slot, WifiIconState state)</span> &#123;</span><br><span class="line">            <span class="comment">// 创建一个StatusBarWifiView </span></span><br><span class="line">            <span class="type">StatusBarWifiView</span> <span class="variable">view</span> <span class="operator">=</span> onCreateStatusBarWifiView(slot);</span><br><span class="line">            view.applyWifiState(state);</span><br><span class="line">            <span class="comment">// 将view 添加进ViewGroup</span></span><br><span class="line">            mGroup.addView(view, index, onCreateLayoutParams());</span><br><span class="line">            <span class="keyword">if</span> (mIsInDemoMode) &#123;</span><br><span class="line">                mDemoStatusIcons.addDemoWifiView(state);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> view;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">private</span> StatusBarWifiView <span class="title function_">onCreateStatusBarWifiView</span><span class="params">(String slot)</span> &#123;</span><br><span class="line">            <span class="type">StatusBarWifiView</span> <span class="variable">view</span> <span class="operator">=</span> StatusBarWifiView.fromContext(mContext, slot);</span><br><span class="line">            <span class="keyword">return</span> view;</span><br><span class="line">        &#125;</span><br><span class="line">    </span><br><span class="line">        ....</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onSetIconHolder</span><span class="params">(<span class="type">int</span> viewIndex, StatusBarIconHolder holder)</span> &#123;</span><br><span class="line">            <span class="keyword">switch</span> (holder.getType()) &#123;</span><br><span class="line">                <span class="keyword">case</span> TYPE_ICON:</span><br><span class="line">                    onSetIcon(viewIndex, holder.getIcon());</span><br><span class="line">                    <span class="keyword">return</span>;</span><br><span class="line">                <span class="keyword">case</span> TYPE_WIFI:</span><br><span class="line">                    onSetSignalIcon(viewIndex, holder.getWifiState());</span><br><span class="line">                    <span class="keyword">return</span>;</span><br><span class="line">                <span class="keyword">case</span> TYPE_MOBILE:</span><br><span class="line">                    onSetMobileIcon(viewIndex, holder.getMobileState());</span><br><span class="line">                <span class="keyword">default</span>:</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onSetSignalIcon</span><span class="params">(<span class="type">int</span> viewIndex, WifiIconState state)</span> &#123;</span><br><span class="line">            <span class="type">StatusBarWifiView</span> <span class="variable">wifiView</span> <span class="operator">=</span> (StatusBarWifiView) mGroup.getChildAt(viewIndex);</span><br><span class="line">            <span class="keyword">if</span> (wifiView != <span class="literal">null</span>) &#123;</span><br><span class="line">                wifiView.applyWifiState(state);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (mIsInDemoMode) &#123;</span><br><span class="line">                mDemoStatusIcons.updateWifiState(state);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        ....</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这里根据不同的StatusBarIconHolder类型，设置不同的网络Icon，上面列出了 Wifi 图标相关的方法。<br>SystemUI状态栏图标根据源码可大体分为三种：</p>
<ol>
<li>StatusBarIconView</li>
<li>StatusBarWifiView</li>
<li>StatusBarMobileView</li>
</ol>
<p>这里主要以Wifi 相关图标（StatusBarWifiView）进行分析，添加Icon时首先会创建一个<br>StatusBarWifiView，然后调用StatusBarWifiView的applyWifiState更新其显示状态，最后将其加入到CollapsedStatusBarFragment中放置Icon的ViewGroup中，这样就完成了添加过程；<br>再来看看 CollapsedStatusBarFragment：<br><strong>SystemUI/src/com/android/systemui/statusbar/phone/CollapsedStatusBarFragment.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CollapsedStatusBarFragment</span> <span class="keyword">extends</span> <span class="title class_">Fragment</span> <span class="keyword">implements</span> <span class="title class_">CommandQueue</span>.Callbacks &#123;</span><br><span class="line">    ....</span><br><span class="line">    <span class="keyword">private</span> DarkIconManager mDarkIconManager;</span><br><span class="line">    ....</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> View <span class="title function_">onCreateView</span><span class="params">(LayoutInflater inflater, <span class="meta">@Nullable</span> ViewGroup container,</span></span><br><span class="line"><span class="params">            Bundle savedInstanceState)</span> &#123;</span><br><span class="line">        <span class="keyword">return</span> inflater.inflate(R.layout.status_bar, container, <span class="literal">false</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">onViewCreated</span><span class="params">(View view, <span class="meta">@Nullable</span> Bundle savedInstanceState)</span> &#123;</span><br><span class="line">        ....</span><br><span class="line">        <span class="comment">// 这里可以看出status_bar布局中的statusIcons就是我们展示各种Icon的区域</span></span><br><span class="line">        mDarkIconManager = <span class="keyword">new</span> <span class="title class_">DarkIconManager</span>(view.findViewById(R.id.statusIcons));</span><br><span class="line">        mDarkIconManager.setShouldLog(<span class="literal">true</span>);</span><br><span class="line">        Dependency.get(StatusBarIconController.class).addIconGroup(mDarkIconManager);</span><br><span class="line">        ....   </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>补充：<br>notifyListenersIfNecessary()在其父类SignalController中定义，<br><strong>frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/policy/SignalController.java</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> CallbackHandler mCallbackHandler;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">notifyListenersIfNecessary</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="keyword">if</span> (isDirty()) &#123;</span><br><span class="line">            saveLastState();</span><br><span class="line">            notifyListeners();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 在这里注意了，在这里的的参数是 CallbackHandler 的对象</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">final</span> <span class="keyword">void</span> <span class="title function_">notifyListeners</span><span class="params">()</span> &#123;</span><br><span class="line">        notifyListeners(mCallbackHandler);</span><br><span class="line">    &#125;</span><br><span class="line"><span class="comment">// callback 则是 CallbackHandler 的对象。</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title function_">notifyListeners</span><span class="params">(SignalCallback callback)</span>;</span><br></pre></td></tr></table></figure>
<p>CallbackHandler维护了所有需要监听的SignalCallback接口对象,我们的StatusBarSignalPolicy就实现了该接口。<br>StatusBarSignalPolicy主要执行网络图标的刷新动作，其实现了NetworkControllerImpl.SignalCallback接口,然后注册到NetworkController,其具体实现类NetworkControllerImpl会根据WIFI,SIM等状态广播来进一步派发给具体的Controller,例如WifiSignalController,每个Controller只与CallbackHandler交互,然后CallbackHandler继续转交给维护的SignalCallback接口的具体实现类,例如StatusBarSignalPolicy</p>

      
      <blockquote>
        
        <strong>本文链接：</strong><br><a href="http://longzhiye.top/2023/11/26/2023-11-26/">http://longzhiye.top/2023/11/26/2023-11-26/</a>
      </blockquote>
    </div>
    <footer class="mdui-card-actions">
      
        <a class="mdui-ripple article_categories-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a>
      
      
        <a class="mdui-ripple article_tags-link" href="/tags/Android/" rel="tag">Android</a><a class="mdui-ripple article_tags-link" href="/tags/SystemUI/" rel="tag">SystemUI</a><a class="mdui-ripple article_tags-link" href="/tags/framework/" rel="tag">framework</a>
      
    </footer>
    
  </article>
  
<script src="//cdn.bootcdn.net/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.bootcdn.net/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

  <script>$("#main article .mdui-card-content img.fancybox").on("click",function(e){$.fancybox.open({src:$(this).attr("src")});});</script>


  <nav id="paginator">
    
      <a rel="prev" class="extend prev" href="/2023/12/02/2023-12-02/">
        <button aria-label="prev" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></button>
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android10.0 最近任务Recents功能分析'}">上一篇</span>
      </a>
    
    <div class="spacer"></div>
    
      <a rel="next" class="extend next" href="/2023/11/25/2023-11-25/">
        <span class="mdui-p-x-3" mdui-tooltip="{content: 'Android 10.0 Launcher 启动流程'}">下一篇</span>
        <button aria-label="next" class="mdui-btn mdui-btn-raised mdui-btn-icon mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_forward</i></button>
      </a>
    
  </nav>





</main>
  <footer id="footer" class="mdui-m-t-5 mdui-p-y-3 mdui-color-theme">
  <div class="mdui-p-y-0 mdui-text-center">
    
    
    
    
    
    
    
      <a href="http://github.com/longzhiye" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe7ab;</i></a>
    
    
    
      <a href="https://www.zhihu.com/people/long-zhi-xie-61" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe6c0;</i></a>
    
    
    
      <a href="tencent://tencent:////message/?uin=951898105&Menu=yes" target="_blank" class="mdui-btn mdui-btn-icon mdui-text-color-theme-a100"><i class="mdui-icon iconfont">&#xe651;</i></a>
    
    
  </div>
  <div class="mdui-p-y-1 mdui-text-center">
    Copyright &copy; 2022 - 2025 龙之叶<br>
    Powered by <a href="https://hexo.io/" target="_blank" class="mdui-text-color-theme-accent">Hexo</a>
    <br>
      <span id="busuanzi_container_site_pv" style="display: none;"><i class="iconfont">&#xe7fd;</i> <span id="busuanzi_value_site_pv"></span></span> &nbsp;&nbsp;
      <span id="busuanzi_container_site_uv" style="display: none;"><i class="iconfont">&#xe601;</i> <span id="busuanzi_value_site_uv"></span></span>
    
  </div>
</footer>

  <button id="gotop" class="mdui-fab mdui-fab-fixed mdui-fab-hide mdui-color-theme-accent mdui-ripple"><i class="mdui-icon material-icons">arrow_upward</i></button>
  <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  
<script src="/js/mdui.js"></script>
<script src="/js/script.js"></script>

  
<script src="/custom.js"></script>

</body>
</html>
